package org.zpmis.api.http;

import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.zpmis.api.business.ProjectTaskWebService;
import org.zpmis.common.base.BaseController;
import org.zpmis.common.exception.BusinessException;
import org.zpmis.common.result.PlatformResult;
import org.zpmis.domain.project.qo.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
* created with CodeGenerator
* description:
* @author  Yang
* date: 2021-6-2
* time: 14:53:29
*/
@RestController
@RequestMapping("/task")
@Slf4j
public class ProjectTaskController extends BaseController{

    @Resource
    private ProjectTaskWebService projectTaskWebService;


    /**
     * 新增项目任务
     * @param addProjectTaskQo
     * @return
     */
    @PostMapping("/addProjectTask")
    public PlatformResult addProjectTask(@Validated @RequestBody AddProjectTaskQo addProjectTaskQo){
        try {
            projectTaskWebService.addProjectTask(addProjectTaskQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[ProjectTaskController]---addProjectTask--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[ProjectTaskController]---addProjectTask--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 修改项目任务
     * @param editProjectTaskQo
     * @return
     */
    @PostMapping("/editProjectTask")
    public PlatformResult editProjectTask(@Validated @RequestBody EditProjectTaskQo editProjectTaskQo){
        try {
            projectTaskWebService.editProjectTask(editProjectTaskQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[ProjectTaskController]---editProjectTask--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[ProjectTaskController]---editProjectTask--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 项目任务 逻辑删除 只有新建的任务状态才可以删除
     * @param delProjectTaskQo
     * @return
     */
    @PostMapping("/delProjectTask")
    public PlatformResult delProjectTask(@Validated @RequestBody DelProjectTaskQo delProjectTaskQo){
        try {
            projectTaskWebService.delProjectTask(delProjectTaskQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[ProjectTaskController]---delProjectTask--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[ProjectTaskController]---delProjectTask--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 项目任务列表查询
     * @param projectTaskListQo
     * @return
     */
    @PostMapping("/projectTaskList")
    public PlatformResult projectTaskList(@RequestBody ProjectTaskListQo projectTaskListQo){
        try {
            return PlatformResult.success(projectTaskWebService.projectTaskList(projectTaskListQo));
        } catch (BusinessException e) {
            log.error("[ProjectTaskController]---projectTaskList--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[ProjectTaskController]---projectTaskList--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 项目任务指派给某个人
     * @param projectTaskAssignQo
     * @return
     */
    @PostMapping("/projectTaskAssign")
    public PlatformResult projectTaskAssign(@Validated @RequestBody ProjectTaskAssignQo projectTaskAssignQo){
        try {
            projectTaskWebService.projectTaskAssign(projectTaskAssignQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[ProjectTaskController]---projectTaskAssign--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[ProjectTaskController]---projectTaskAssign--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 任务工作记录 修改，修改指定的字段
     * @param editWorkRecordQo
     * @return
     */
    @PostMapping("/editWorkRecord")
    public PlatformResult editWorkRecord(@Validated @RequestBody EditWorkRecordQo editWorkRecordQo){
        try {
            projectTaskWebService.editWorkRecord(editWorkRecordQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[ProjectTaskController]---editWorkRecord--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[ProjectTaskController]---editWorkRecord--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 任务转交 同 任务指派
     * @param projectTaskAssignQo
     * @return
     */
    @PostMapping("/taskTransfer")
    public PlatformResult taskTransfer(@Validated @RequestBody ProjectTaskAssignQo projectTaskAssignQo){
        try {
            projectTaskWebService.projectTaskAssign(projectTaskAssignQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[ProjectTaskController]---taskTransfer--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[ProjectTaskController]---taskTransfer--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 子任务查询(递归格式返回)
     * @param subTaskQueryQo
     * @return
     */
    @PostMapping("/subTaskQuery")
    public PlatformResult subTaskQuery(@Validated @RequestBody SubTaskQueryQo subTaskQueryQo){
        try {
            return PlatformResult.success(projectTaskWebService.subTaskQuery(subTaskQueryQo));
        } catch (BusinessException e) {
            log.error("[ProjectTaskController]---subTaskQuery--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[ProjectTaskController]---subTaskQuery--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 任务详情查询
     * @param subTaskQueryQo
     * @return
     */
    @PostMapping("/taskDetail")
    public PlatformResult taskDetail(@Validated @RequestBody SubTaskQueryQo subTaskQueryQo){
        try {
            return PlatformResult.success(projectTaskWebService.taskDetail(subTaskQueryQo));
        } catch (BusinessException e) {
            log.error("[ProjectTaskController]---taskDetail--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[ProjectTaskController]---taskDetail--->Exception:",e);
            return PlatformResult.failure();
        }
    }
}
